// StandardGenerator.h: interface for the StandardGenerator class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_STANDARDGENERATOR_H__42581392_B115_4DFD_BA86_D3EC5EC37430__INCLUDED_)
#define AFX_STANDARDGENERATOR_H__42581392_B115_4DFD_BA86_D3EC5EC37430__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "Standard.h"
#include "ProductCatalog.h"
#include "ManagerTemplate.h"
#include "ProductCatalogManager.h"
#include "StandardOfClamp.h"
#include "StandardOfSA.h"
#include "StandardOfSpring.h"
#include "StandardOfConstSpring.h"
#include "StandardOfConnect.h"
#include "StandardOfBoltNut.h"
#include "StandardOfAttach.h"
#include "StandardOfProfiledBar.h"

class AFX_EXT_CLASS StandardGenerator : public ManagerTemplate<CString, Standard> 
{
public:
	StandardGenerator();
	virtual ~StandardGenerator();

public:
	Standard* Generate(JointSystem::ProductCatalog* pCatalog);

	template <class StandardType> StandardType* Generate(const CString& strStandard, StandardType* pType)
	{
		ASSERT(!strStandard.IsEmpty());
		ProductCatalog* pCatalog = ProductCatalogManager::Instance()->
			GetProductCatalog(strStandard);
		ASSERT(pCatalog);
		
		Standard* pStandard = Generate(pCatalog);
		ASSERT(pStandard);
				
		return static_cast<StandardType*>(pStandard);
	}

private:
	template <class StandardType> StandardType& InitStandard(StandardType& standard, JointSystem::ProductCatalog* pCatalog)
	{
		ASSERT(pCatalog);

		standard.SetDBSourceURL(pCatalog->DataSourceURI());
		standard.SetInfoTable(pCatalog->InfoTable());
		standard.SetStandard(pCatalog->ID());

		_RecordsetPtr rs;
		try
		{
			if(GetStandardDataSet(standard, rs))
				ReadDataForObject(rs, standard);
			
			rs->Close();
		}
		CATCH_COM_ERROR(rs, standard)
		return standard;
	}

private:
	BOOL GetStandardDataSet(Standard& standard, _RecordsetPtr& rs);

	void ReadDataForObject(const _RecordsetPtr& rs, StandardOfClamp& standard);
	void ReadDataForObject(const _RecordsetPtr& rs, StandardOfSA& standard);
	void ReadDataForObject(const _RecordsetPtr& rs, StandardOfConnect& standard);
	void ReadDataForObject(const _RecordsetPtr& rs, StandardOfConstSpring& standard);
	void ReadDataForObject(const _RecordsetPtr& rs, StandardOfSpring& standard);
	void ReadDataForObject(const _RecordsetPtr& rs, StandardOfBoltNut& standard);
	void ReadDataForObject(const _RecordsetPtr& rs, StandardOfAttach& standard);
	void ReadDataForObject(const _RecordsetPtr& rs, StandardOfProfiledBar& standard);
	void ReadData(const _RecordsetPtr& rs, Standard& standard);

private:
	Standard* GenerateNew(JointSystem::ProductCatalog* pCatalog);
};

#endif // !defined(AFX_STANDARDGENERATOR_H__42581392_B115_4DFD_BA86_D3EC5EC37430__INCLUDED_)
